package com.google.code.ptrends.entities;

import org.apache.commons.lang.StringUtils;

public class ItemValueRecord {
	private int parametrID;
	private String value;
	private int fHashCode;
	
	public void setParametrID(int parametrID) {
		this.parametrID = parametrID;
	}

	public int getParametrID() {
		return parametrID;
	}

	public void setValue(String value) {
		if (StringUtils.isBlank(value)) {
			throw new IllegalArgumentException("Illegal null or blank value");
		}

		this.value = value;
	}

	public String getValue() {
		return value;
	}

	@Override
	public int hashCode() {
		if (fHashCode == 0) {
			fHashCode = 7 + 11 * parametrID;
		}
		if (value != null) {
			fHashCode ^= 23 + value.hashCode();
		}
		return fHashCode;
	}

	@Override
	public boolean equals(Object arg0) {
		if (arg0 == null)
			return false;
		if (!(arg0 instanceof ItemValueRecord))
			return false;
		ItemValueRecord obj = (ItemValueRecord) arg0;
		boolean result = parametrID == obj.getParametrID();

		if (value == null) {
			result &= obj.getValue() == null;
		} else {
			result &= value.equals(obj.getValue());
		}
		return result;
	}

}
